package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.entity.Restocking;
import com.situ.feemanagement.pojo.query.RestockingQuery;
import com.situ.feemanagement.service.IRestockingService;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/restocking")
public class RestockingController {

    @Autowired
    private IRestockingService restockingService;

    @GetMapping("/list")
    public Result list(RestockingQuery restockingQuery) {
        Map<String, Object> map = restockingService.selectByPage(restockingQuery);
        return Result.ok(map);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        restockingService.deleteById(id);
        return Result.ok("删除成功");
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids) {
        restockingService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @PostMapping("/add")
    public Result add(@RequestBody Restocking restocking) {
        restockingService.add(restocking);
        return Result.ok("添加成功");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Restocking restocking = restockingService.selectById(id);
        return Result.ok(restocking);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Restocking restocking) {
        restockingService.update(restocking);
        return Result.ok("更新成功");
    }
}
